package com.example.demo.service;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.mapper.PsLineMapper;
import com.example.demo.model.PsLine;
import com.example.demo.repository.LineRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LineServiceImpl implements LineRepository {

    @Autowired
    private PsLineMapper psLineMapper;


    @Qualifier("psLineMapper")
    @Autowired
    private BaseMapper baseMapper;


    public List<PsLine> getLine( Double coorx,  Double coory,  Integer distance) {
        List<PsLine> lineList = psLineMapper.selectByPoint(coorx, coory, distance);
        return lineList;
    }

    public List<PsLine> getLineByExtent( Double minx,  Double miny,  Double maxx,  Double maxy) {
        List<PsLine> lineList = psLineMapper.selectByExtend(minx, miny, maxx, maxy);
        return lineList;
    }


    public Boolean updateGeom(Integer gid,String geom) {
        try{
            PsLine entity = new PsLine();
            entity.setGeom(geom);
            UpdateWrapper<PsLine> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("gid", gid);
            int rows = baseMapper.update(entity, updateWrapper);
            return rows > 0;
        }catch (Exception exception){
            return false;
        }

    }
}
